import {redirect} from "react-router-dom";
import api from "@/api/index.js"

export default async function articleEditAction({request, params}) {
    const {slug} = params;
    const fromdata = await request.formData();
    const fromobj = Object.fromEntries(fromdata);
    if (fromobj.tags) {
        fromobj.tags = fromobj.tags.split(',');
    }
    const response = await api.article.updateArticle(fromobj,slug)
    if(response && response.status !==1){
        throw new Error(response.message) // 给错误页面捕获
    }


    return redirect(`/article/${slug}`);
}